package control
{
	import flash.events.Event;
	import model.ModelLocator;
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	public class ShareMarker
	{
		internal var theModel:ModelLocator = ModelLocator.getInstance();
		private var ShareMarkerRO:RemoteObject;
		public function ShareMarker()
		{
			ShareMarkerRO = new RemoteObject();
			ShareMarkerRO.destination="ShareMarker";
			ShareMarkerRO.doShareMarker.addEventListener(ResultEvent.RESULT,ShareMarkerResultHandler);
			ShareMarkerRO.addEventListener(FaultEvent.FAULT, ShareMarkerFaultHandler);
		}
		
		public function doShareMarker(markerid:String):void
		{
			ShareMarkerRO.doShareMarker(markerid,theModel.user.user_id);
		}
		
		internal function ShareMarkerResultHandler(event:ResultEvent):void
		{
				if( event.result.state as String == "successful")
					Alert.show("share marker successful");
				else if(event.result.state as String == "exist")
					Alert.show("already shared");
				theModel.allShowAllShareMarkers = event.result.markers as ArrayCollection;
				theModel.dispatchEvent(new Event(ModelLocator.SHAREMARKER_OK));
		}
		
		internal function ShareMarkerFaultHandler(event:ResultEvent):void
		{
			Alert.show("error occur when show the shared markers");
		}
	}
}